#coding=utf8
#-------------------------------------------------------------------------------
# Name:        ??1
# Purpose:
#
# Author:      weigun
#
# Created:     11-08-2011
# Copyright:   (c) weigun 2011
# Licence:     <your licence>
#-------------------------------------------------------------------------------
#!/usr/bin/env python
import os,sys

from optparse import OptionParser

def show_help(parser):
    parser.print_help()
    exit(0)

class Options(object):
    """
        class comment
    """
    FREE_GET = 'freeget'
    GET_ALL = 'getall'
    ANALYSIS = 'analysis'
    CRASH_DEVICES = 'crashdevices'

    def __init__(self,parser):
        self._op,args = parser.parse_args()
        if self._op.bugs_with_logs is not None:
            self._op.bugs_with_logs = map(lambda t:(int(t) * 1000) + 3,self._op.bugs_with_logs)
        self._op.bugs_list = self._op.bugs_with_logs + self._op.bugs_without_logs
        if not self._op.version:
            show_help(parser)
        if not self._op.analysis and  not self._op.bugs_list and not self._op.is_getall and not self._op.is_crashdevices:
            show_help(parser)
        self._op.appname = unicode(self._op.appname,'gbk')
        self.type = 'freeget'
        if self._op.analysis:
            self.type = 'analysis'
        elif self._op.is_getall:
            self.type = 'getall'
        elif self._op.bugs_list:
            self.type = 'freeget'
        elif self._op.is_crashdevices:
            self.type = self.CRASH_DEVICES

    def get_type(self):
        return self.type

    def __getattr__(self,name):
        try:
            return getattr(self._op,name)
        except Exception:
            raise IndexError,"option[%s] not found"%(name)






class CmdArgs(object):
    """
        class comment
    """
    usage = "usage: %prog -n tksj -v 1.3.1.3 -b 123 -b 745 -b 866 --bl 6666"
    def __init__(self):
        self.parser = OptionParser(usage = self.usage)

    def parse(self):
        parser = self.parser
        parser.add_option("-v", "--version", action="store",dest="version",default=False,help=u"制定抓取的版本号")
        parser.add_option("-b", "--bugs", action="append",dest="bugs_without_logs",default=[],help=u"需要抓取的CrashId,支持多个(该参数不抓系统log)")
        parser.add_option("--bl", "--logbugs", action="append",dest="bugs_with_logs",default=[],help=u"需要抓取的CrashId,支持多个(该参数会抓系统log),未开放使用")
        parser.add_option("-a", "--analysis", action="store_true",dest="analysis",default=False,help=u"统计最新影响率:当前累计影响用户/累计使用用户")
        parser.add_option("-n", "--name", action="store",dest="appname",default='',help=u"抓取的项目名字")
        parser.add_option("-i", "--ignore", action="append",dest="ignore_bugs",default=[],help=u"需要忽略的crash列表,待实现")
        parser.add_option("--ga", "--getall", action="store_true",dest="is_getall",default=False,help=u"所有crash不放过,nativeCrash除外，但不抓系统log")
        parser.add_option("--cd", "--crashdevices", action="store_true",dest="is_crashdevices",default=False,help=u"统计java与navite型闪退的机型")



        return Options(parser)


options = CmdArgs().parse()



if __name__ == '__main__':
    op =  CmdArgs().parse()
    print op.is_getall

